package three;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-01
 * Time: 23:06
 */

public class Demo3 {
    public static void main(String[] args) {
        //通过set方法 依赖传递
        Chang chang = new Chang();
        OpenAndClose2 openAndClose2 = new OpenAndClose2();
        //先要调用set方法
        openAndClose2.setTv(chang);
        openAndClose2.open();
    }
}

class Chang implements ITV2{
    @Override
    public void play() {
        System.out.println("电视打开");
    }
}


//通过 setter方法 传递
interface IOpenAndClose2{
    public void open(); //抽象方法

    public void setTv(ITV2 tv); //setTv 实现了接口对象实列
}

interface ITV2{ //ITV 接口
    public void play();
}

class OpenAndClose2 implements IOpenAndClose2{
    private ITV2 tv; //成员

    public void setTv(ITV2 tv){
        this.tv = tv;
    }
    public void open(){
        this.tv.play();
    }
}